<?php

class View extends Core {
	public function __call($name, $arguments) {
		if (!method_exists($this, $name)) {
			$helpers = glob(HELPER . '*.php', GLOB_BRACE);
			foreach ($helpers as $helper) {
				require_once $helper;
				$class = str_replace(array(HELPER, '.php'), '', $helper);
				$class = str_replace(' ', '', humanize($class));
				if (method_exists($class, $name)) {
				    return call_user_func_array(array(new $class, $name), $arguments);
				}
			}
		}
	}
	
	public function render($page, $template) {
		$theme_path = THEME . $this->Config->theme . DS;
		if (is_ajax()) {
			return require_once $theme_path . $page;
		} else {
			ob_start();
			require_once $theme_path . $page;
			$this->content = ob_get_clean();
			if (File::exists($theme_path . $template)) {
				return require_once $theme_path . $template;
			}
		}
	}
}

?>